#!/bin/bash
#
# Copyright 2015-2017 Adrian DC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# === Standalone Source Helper ===
# source <(curl -Ls https://github.com/AdrianDC/android_development_shell_tools/raw/master/android_adb_updater.rc)

# === ADB Binaries Updater ===
function adbupdate()
{
  # Usage: adbupdate (adb binary update from upstream)

  # Check adb version
  adb version;

  # Detect built ROM's adb
  if [ -f ./out/host/linux-x86/bin/adb ]; then
    sudo rm -f /usr/bin/adb;
    sudo cp ./out/host/linux-x86/bin/adb /usr/bin/adb;
  else
    sudo rm -f /usr/bin/adb;
    wget -O - https://skia.googlesource.com/skia/+archive/cd048d18e0b81338c1a04b9749a00444597df394/platform_tools/android/bin/linux.tar.gz | tar -zxvf - adb;
    sudo mv adb /usr/bin/adb;
  fi;

  # Update permissions and check adb version
  sudo chmod +x /usr/bin/adb;
  adb version;
}
